package cn.csg.iotplatform.module.system.api.manufacture;

import cn.csg.iotplatform.framework.common.pojo.CommonResult;
import cn.csg.iotplatform.framework.common.util.object.BeanUtils;
import cn.csg.iotplatform.module.system.controller.admin.manufacturer.vo.ManufacturerVO;
import cn.csg.iotplatform.module.system.dal.dataobject.manufacturer.ManufacturerDO;
import cn.csg.iotplatform.module.system.manufacturer.ManufacturerApi;
import cn.csg.iotplatform.module.system.manufacturer.dto.ManufacturerRespDTO;
import cn.csg.iotplatform.module.system.service.manufacturer.ManufacturerService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.List;

import static cn.csg.iotplatform.framework.common.pojo.CommonResult.success;

/**
 * @Author Andy
 * @Date 2024/4/7
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ManufacturerApiImpl implements ManufacturerApi {
    @Resource
    private ManufacturerService manufacturerService;

    @Override
    public CommonResult<ManufacturerRespDTO> getDeviceManufacturerByIdAsynVersion(String id, String authorization) {
        ManufacturerVO manufacturerDO = manufacturerService.getManufacturer(id);
        return success(BeanUtils.toBean(manufacturerDO, ManufacturerRespDTO.class));
    }

    @Override
    public CommonResult<ManufacturerRespDTO> getDeviceManufacturerByName(String name) {
        ManufacturerDO manufacturerDO = manufacturerService.getDeviceManufacturerByName(name);
        return success(BeanUtils.toBean(manufacturerDO, ManufacturerRespDTO.class));
    }

    @Override
    public CommonResult<List<ManufacturerRespDTO>> getDeviceManufacturer() {
        List<ManufacturerRespDTO> manufacturerList = manufacturerService.getDeviceManufacturer();
        return success(manufacturerList);
    }
}
